local jushou = fk.CreateSkill({
  name = "rainveil__jushou",
})

Fk:loadTranslationTable{
  ["rainveil__jushou"] = "易守",
  [":rainveil__jushou"] = "结束阶段，你可以与一名其他角色交换手牌，然后手牌数较多的一方翻面。",
  ["#rainveil__jushou-choose"] = "易守：你可以与一名其他角色交换手牌，然后手牌数较多的一方翻面",

  ["$rainveil__jushou1"] = "白马沉河共歃誓，怒涛没城亦不悔！",
}

jushou:addEffect(fk.EventPhaseEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jushou.name) and #player.room:getOtherPlayers(player, false) > 0 and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "#rainveil__jushou-choose",
      skill_name = jushou.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:swapAllCards(player, { player, to }, jushou.name, "h")
    if player:getHandcardNum() > to:getHandcardNum() then
      player:turnOver()
    else
    if player:getHandcardNum() < to:getHandcardNum() then
      to:turnOver()
    end
   end
  end,
})

return jushou
